from django.db import models


# Create your models here.
class BookInfo(models.Model):
    # 主键系统自动增加
    name = models.CharField(max_length=10)
    pub_date = models.DateField(null=True)
    readcount = models.IntegerField(default=0)
    commentcount = models.IntegerField(default=0)
    is_delete = models.BooleanField(default=False)

    class Meta:
        db_table = 'bookinfo'  # 修改表名

    def __str__(self):
        return self.name


class PeopleInfo(models.Model):
    # 选择的列表
    GENDER_CHOICES = (
        (0, 'male'),
        (1, 'female')
    )
    name = models.CharField(max_length=10)
    description = models.CharField(max_length=200)
    gender = models.SmallIntegerField(choices=GENDER_CHOICES, default=0)
    is_delete = models.BooleanField(default=False)

    # 外键 设置为null， 拒绝删除，
    # CASCADE级联 ，删除主表数据，外键表中的而数据一起删除
    book = models.ForeignKey(BookInfo, on_delete=models.CASCADE)

    class Meta:
        db_table = 'peopleinfo' # 修改表名为peopleinfo

    def __str__(self):
        return self.name
